<template>
	<view class="pics">
		<scroll-view class="left" scroll-y="true" >
			<view :class="index===activeIndex?'active':''" 
			v-for="(item,index) in picsCate" :key="item.id"
			@click="leftClickHandle(index,item.id)">
				{{item.title}}
			</view>
		</scroll-view>
		<scroll-view class="right" scroll-y="true" >
			<view class="item" v-for="(item,index) in secondData" :key="index">
				<image @click="previewImage(item.img_url)" :src="item.img_url"></image>
				<text>{{item.title}}</text>
			</view>
			<text v-if="secondData.length===0">暂无数据</text>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				picsCate:[],
				activeIndex:0,
				secondData:[]
			}
		},
		methods: {
			async getPicsCate(){
				const res = await this.$http({url:"/api/getimgcategory"})
				this.picsCate = res.data.message
				this.leftClickHandle(0,this.picsCate[0].id)
			},
			async leftClickHandle(index,id){
				this.activeIndex = index
				//获取右侧的数据
				const res = await this.$http({url:"/api/getimages/"+id})
				this.secondData = res.data.message
			},
			previewImage(current){
				let imgUrls = this.secondData.map(item=>{
					return item.img_url
				})
				uni.previewImage({
					current:current,
					urls:imgUrls
				})
			}
		},
		onLoad() {
			this.getPicsCate()
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.pics{
		height: 100%;
		.left{
			display: inline-block;
			height: 100%;
			width: 200rpx;
			border-right: 1px solid #eee;
			view{
				text-align: center;
				line-height: 120rpx;
				border-bottom: 1px solid #eee;
				color: #342f2f;
				font-size: 30rpx;
			}
		}
		.right{
			display: inline-block;
			height: 100%;
			width: 500rpx;
			padding-left: 20rpx;
			.item{
				image{
					width: 100%;
					border-radius: 5px;
				}
				text{
					font-size: 30rpx;
					line-height: 60rpx;
				}
			}
		}
	}
	.active{
		background-color: $shop-color;
		color: #fff !important;
	}
</style>
